$(function() {
	/**
	 * tabpage
	 **/
    Sys.initTabPage("tabpanel", {
        height: function() {
            var winHeight = $(window).height(),
            headerHeight = $(".main-header:visible").outerHeight(),
            footerHeight = $(".main-footer:visible").outerHeight(),
            contentHeight = winHeight - headerHeight - footerHeight;
            return contentHeight < 300 ? 300 : contentHeight
        }
    });
    Sys.addTabPage('<i class="fa fa-home"></i> 确诊病例', Sys.backendPath+"/home", false);
    $(document).on("click", ".addTabPage", function(e) {
        var $this = $(this),
        href = $this.data("href"),
        title = $this.html() || $this.data("title") || $this.attr("title") || $this.text() ;
        if (href && href != "" && href != "blank") {
            Sys.addTabPage($.trim(title || "新页签"), href,true);
            if ($this.parent().hasClass("treeview")) {
                window.location.hash = href.replace("#", "")
            }
        }
    });
    $(document).on("click", '[data-toggle="push-menu"]', function(e) {
    	$(".tabpanel").css("width","100%");
    	$(".tabpanel_tab_content").css("width","100%");
    	$(".tabpanel_move_content").css("width","100%");
    	$(".tabpanel_content").css("width","100%");
        window.setTimeout(function() {
        	$(window).resize();
        },2500);
    });

	/**
	 * fullScreen
	 **/
    $("#fullScreen").click(function() {
        if ($(this).data("isOpen") == "true") {
            $(this).data("isOpen", "false");
            if (document.exitFullscreen) {
                document.exitFullscreen()
            } else {
                if (document.msExitFullscreen) {
                    document.msExitFullscreen()
                } else {
                    if (document.mozCancelFullScreen) {
                        document.mozCancelFullScreen()
                    } else {
                        if (document.webkitCancelFullScreen) {
                            document.webkitCancelFullScreen()
                        }
                    }
                }
            }
        } else {
            $(this).data("isOpen", "true");
            var _obj = document.documentElement;
            if (_obj.requestFullscreen) {
            	_obj.requestFullscreen()
            } else {
                if (_obj.msRequestFullscreen) {
                	_obj.msRequestFullscreen()
                } else {
                    if (_obj.mozRequestFullScreen) {
                    	_obj.mozRequestFullScreen()
                    } else {
                        if (_obj.webkitRequestFullScreen) {
                        	_obj.webkitRequestFullScreen()
                        }
                    }
                }
            }
        }
        return false
    });
    
	/**
	 * skin
	 **/
    var my_skins = [
      "skin-blue",
      "skin-black",
      "skin-red",
      "skin-yellow",
      "skin-purple",
      "skin-green",
      "skin-blue-light",
      "skin-black-light",
      "skin-red-light",
      "skin-yellow-light",
      "skin-purple-light",
      "skin-green-light"
    ];
    //init
    function initSkin(){
        var tmp = get('skin');
        if (tmp && $.inArray(tmp, my_skins))
          change_skin(tmp);
    }
    //Add the change skin listener
    $("[data-skin]").on('click', function (e) {
      if($(this).hasClass('knob'))
        return;
      e.preventDefault();
      change_skin($(this).data('skin'));
    });
    /**
     * Replaces the old skin with the new skin
     * @param String cls the new skin class
     * @returns Boolean false to prevent link's default action
     */
    function change_skin(cls) {
      $.each(my_skins, function (i) {
        $("body").removeClass(my_skins[i]);
      });

      $("body").addClass(cls);
      store('skin', cls);
      return false;
    }
    /**
     * Store a new settings in the browser
     *
     * @param String name Name of the setting
     * @param String val Value of the setting
     * @returns void
     */
    function store(name, val) {
      if (typeof (Storage) !== "undefined") {
        localStorage.setItem(name, val);
      } else {
        window.alert('Please use a modern browser to properly view this template!');
      }
    }
    /**
     * Get a prestored setting
     *
     * @param String name Name of of the setting
     * @returns String The value of the setting | null
     */
    function get(name) {
      if (typeof (Storage) !== "undefined") {
        return localStorage.getItem(name);
      } else {
        window.alert('Please use a modern browser to properly view this template!');
      }
    }
    //init
    initSkin();
});